﻿var helps;
//任务类型
var g_taskType;


function showHelpList(type,pageNo)
{	
	$('#release').css('display','none');
	$('#HelpT').css('display','block');
     //将页面回到顶端
     scroll(0,0);
	 
	//页码赋给全局变量
	g_pageNo=pageNo;
	g_taskType=type;
	//alert(type);
	rush();
	if(userID==""||userID==null)
	{
		alert("请先登录");
		return;
	}
	var url;//申请的服务器端程序地址
	url="help/Require.php?action="+type;
	//alert("type = " + type);
	//alert("userID=" +userID);
	var para="userID="+userID;
	para+="&pageNo="+pageNo;//页码
	para+="&perPageRecord="+g_perPageRecord;//每页显示记录的条目数

	
	resp=SendPostRequest(url,para);
	//alert(resp);
	task();
	
}

function rush()
{
	//$("#helps").show();
	//$("#addhelp").hide();
	helps=document.getElementById('helps');
		//刷新前 先清空子节点
	var childs = helps.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		helps.removeChild(childs[i]);
	}

}


function task()
{
	//alert(resp);
	if(resp!=null || resp != 'false')
	{
		//helps.style.display="block";
		//alert(resp);
		eval("reqObj="+resp);
		g_totalRecord=reqObj.reqCount;
		//向上取整,有小数就整数部分加1
		g_pageCount=Math.ceil(g_totalRecord/g_perPageRecord);
		//alert(g_totalRecord+";"+g_pageCount);
		helpList=reqObj.reqList;
		
		//eval("helpList="+resp);	//比起var actlist， actlist变成了一个全局的变量 可以动态插入
		var countDiv=document.createElement("div");
		countDiv.style.padding="0 0 10px 5px"
		var recordCount=document.getElementById("recordCount");
		recordCount.innerHTML=g_totalRecord;
		
		for(var i=0;i<helpList.length;i++)
		{
			var admincheck;
			if(username!=helpList[i].requesterName)
				admincheck = false;
			else
				admincheck = true;
			var reqDiv=document.createElement("div");
			reqDiv.setAttribute("class","help");	
						
			var id=helpList[i].id;


			var lidiv = document.createElement("li"); 
			if(helpList[i].chooseID>0)
			{
			lidiv.innerHTML = 
			' <div class="r_l_head"><a href="other.html?'+helpList[i].userID+'"><span>发布人<br />'+
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].userID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].requesterName+'</b><br /><font>评分：'+helpList[i].ScoreReq+'</font>'+
			'</span></a></div> '+
			'<div class="r_l_head r_l_headc"><a href="other.html?'+helpList[i].chooseID+'"><span>承接者<br />'+		
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].chooseID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].chooseName+'</b><br />'+
			'<font>评分：'+helpList[i].ScoreChoose+'</font>'+
			'</span></a></div>'+
			'<div class="r_l_c"><b>￥'+helpList[i].money+'</b><strong>&nbsp;<a href="help.htm?'+id+'" target="_blank">'+helpList[i].title+'</a></strong>'+
			'<font color="#dddddd">（242）</font><br	/>'+
			'发布人:<font color="#8ca6d7">'+helpList[i].requesterName+'</font> 分类：<font color="#8ca6d7">'+helpList[i].cate+
			'</font> 发布时间:'+helpList[i].setuptime+'<br />'+
			'任务状态:  <img src="images/icon-ing.gif" width="14" height="14" /> '+helpList[i].statusstr+'<br />'+
			helpList[i].description+
			'</div>';
			}
			else
			{
			
			lidiv.innerHTML = 
			' <div class="r_l_head"><a href="other.html?'+helpList[i].userID+'"><span>发布人<br />'+
			//'<img class="headimg" src="imgpick/uploads/'+helpList[i].userID+'" width="50" height="50" /><br />'+
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].userID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].requesterName+'</b><br /><font>评分：'+helpList[i].ScoreReq+'</font>'+
			'</span></a></div> '+
			'<div class="r_l_head r_l_headc"><span>承接者<br />'+		
			'<b>暂未指定承接人</b><br />'+
			'</span></div>'+
			'<div class="r_l_c"><b>￥'+helpList[i].money+'</b><strong>&nbsp;<a href="help.htm?'+id+'" target="_blank">'+helpList[i].title+'</a></strong>'+
			'<font color="#dddddd">（242）</font><br	/>'+
			'发布人:<font color="#8ca6d7">'+helpList[i].requesterName+'</font> 分类：<font color="#8ca6d7">'+helpList[i].cate+
			'</font> 发布时间:'+helpList[i].setuptime+'<br />'+
			'任务状态:  <img src="images/icon-ing.gif" width="14" height="14" /> '+helpList[i].statusstr+'<br />'+
			helpList[i].description+
			'</div>';		
			}
			helps.appendChild(lidiv);  
		}	
		
		CreatePageList();
	}	
}


function showCateHelpList(cateid,pageNo)
{
	//alert(cateid);
	//如果发生在user.html中 要考虑user_nav的效果
	var sel_on = $(".user_nav .hover");
	sel_on.removeClass("hover");
	var sel = $(".user_nav .default");
	sel.addClass("hover");

	rush();
	var url;//申请的服务器端程序地址
	if(cateid=='allReqList')//随便看看 给出所有的
	{
		url="help/Require.php?action=allReqList";
	}
	else
	{
		url="help/Require.php?action=cateReqList";
	}   //para="&cate="+cateid;

	var para="&cate="+cateid;
	para+="&pageNo="+pageNo;//页码
	para+="&perPageRecord="+g_perPageRecord;//每页显示记录的条目数
	resp=SendPostRequest(url,para);
	//resp=SendPostRequest(url);
	//alert(resp);
	taskNoAdminCheck();
}
function taskNoAdminCheck()
{
		eval("reqObj="+resp);
		g_totalRecord=reqObj.reqCount;
		//向上取整,有小数就整数部分加1
		g_pageCount=Math.ceil(g_totalRecord/g_perPageRecord);
		helpList=reqObj.reqList;
		
		var countDiv=document.createElement("div");
		countDiv.style.padding="0 0 5px 5px"
		var recordCount=document.getElementById("recordCount");
		recordCount.innerHTML=g_totalRecord;

	if(resp!=null || resp != 'false')
	{
		for(var i=0;i<helpList.length;i++)
		{
			var reqDiv=document.createElement("div");
			reqDiv.setAttribute("class","help");	
						
			var id=helpList[i].id;
			var lidiv = document.createElement("li");
			if(helpList[i].chooseID>0)
			{
			lidiv.innerHTML = 
			' <div class="r_l_head"><a href="other.html?'+helpList[i].userID+'"><span>发布人<br />'+
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].userID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].requesterName+'</b><br /><font>评分：'+helpList[i].ScoreReq+'</font>'+
			'</span></a></div> '+
			'<div class="r_l_head r_l_headc"><a href="other.html?'+helpList[i].chooseID+'.jpg"><span>承接者<br />'+		
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].chooseID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].chooseName+'</b><br />'+
			'<font>评分：'+helpList[i].ScoreChoose+'</font>'+
			'</span></a></div>'+
			'<div class="r_l_c"><b>￥'+helpList[i].money+'</b><strong>&nbsp;<a href="help.htm?'+id+'" target="_blank">'+helpList[i].title+'</a></strong>'+
			'<font color="#dddddd">（242）</font><br	/>'+
			'发布人:<font color="#8ca6d7">'+helpList[i].requesterName+'</font> 分类：<font color="#8ca6d7">'+helpList[i].cate+
			//'</font> 时间:2011-05-18 16:28:38<br />'+
			'</font> 发布时间:'+helpList[i].setuptime+'<br />'+
			'任务状态:  <img src="images/icon-ing.gif" width="14" height="14" /> '+helpList[i].statusstr+'<br />'+
			helpList[i].description+
			'</div>';
			}
			else
			{
			lidiv.innerHTML = 
			' <div class="r_l_head"><a href="other.html?'+helpList[i].userID+'"><span>发布人<br />'+
			'<img class="headimg" src="imgpick/uploads/'+helpList[i].userID+'.jpg" width="50" height="50" /><br />'+
			'<b>'+helpList[i].requesterName+'</b><br /><font>评分：'+helpList[i].ScoreReq+'</font>'+
			'</span></a></div> '+
			'<div class="r_l_head r_l_headc"><span>承接者<br />'+		
			'<b>暂未指定承接人</b><br />'+
			'<font>评分：'+helpList[i].ScoreChoose+'</font>'+
			'</span></div>'+
			'<div class="r_l_c"><b>￥'+helpList[i].money+'</b><strong>&nbsp;<a href="help.htm?'+id+'" target="_blank">'+helpList[i].title+'</a></strong>'+
			'<font color="#dddddd">（242）</font><br	/>'+
			'发布人:<font color="#8ca6d7">'+helpList[i].requesterName+'</font> 分类：<font color="#8ca6d7">'+helpList[i].cate+
			//'</font> 时间:2011-05-18 16:28:38<br />'+
			'</font> 发布时间:'+helpList[i].setuptime+'<br />'+
			'任务状态:  <img src="images/icon-ing.gif" width="14" height="14" /> '+helpList[i].statusstr+'<br />'+
			helpList[i].description+
			'</div>';
			}
			helps.appendChild(lidiv);  
		}
	    CreatePageList();
	}	
}

//鼠标滑过头像的放大头像效果

$(function(){
	//var x = 10；
	//var y = 10;
	$('.headimg').live('mouseover',function(e){
		//alert("hhaha");
		var headImgTip = "<div id='headImgTip'><img src=' "+this.src+" '/></div> ";
		$("body").append(headImgTip);
		
		$("#headImgTip").css({
			"top":(e.pageY+5)+"px",
			"left":(e.pageX+5)+"px",
			"height":"200px",
			"width":"200px",
			"position":"absolute"
		}).show("fast");
		
	});
	$('.headimg').live('mouseout',function(){
		$("#headImgTip").remove();
	});
	$('.headimg').live('mousemove',function(e){
		$("#headImgTip").css({
			"top":(e.pageY+5)+"px",
			"left":(e.pageX+5)+"px"
		});
	});	
//鼠标点击头像的效果
	//$('.headimg').live('click',function(e){

	//});	
})

function getiFocusCateList()
{
	var iFocusCateList=document.getElementById('iFocusCateList');	
		//刷新前 先清空子节点
	var childs = iFocusCateList.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		iFocusCateList.removeChild(childs[i]);
	}

	if(userID==""||userID==null)
	{
			var lidiv = document.createElement("li"); 
			lidiv.innerHTML = '<br/><a href="login.html">你还没有登陆</a>'
			iFocusCateList.appendChild(lidiv);	
	}
	else
	{
		var url="user/user.php?action=iFocusCate";
		var para="userID="+userID;
		var resp=SendPostRequest(url,para);
		//alert(resp);
	}
	if(resp!=null && resp != 'false')
	{
		eval("fList="+resp);
		for(var i=0;i<fList.length;i++)
		{
			//var fcate=document.createElement('div');
			//fcate.style.padding="10px";
			//fcate.innerHTML="<li><font style='14px bold'>"+fList[i].name+"</font></li>";
			//iFocusCateList.appendChild(fcate);		
			var lidiv = document.createElement("li"); 
			lidiv.innerHTML = '<a href="#">'+fList[i].name+'</a><B>×</B>';
			//lidiv.innerHTML = '<a href="#">'+fList[i].name+'</a><em>X</em>';
			lidiv.setAttribute("id",fList[i].id);
			//alert('name'+fList[i].name+'  id'+fList[i].id)
			lidiv.onclick = function(){showCateHelpList(this.getAttribute("id"));}

			iFocusCateList.appendChild(lidiv);	

		}
		if(i==0)
		{
			//var fcate=document.createElement('div');
			//fcate.style.padding="10px";
			//fcate.innerHTML="<li><a href='index.html'><font style='16px bold'>"+"赶紧关注一个分类吧"+"</font></a></li>";
			//iFocusCateList.appendChild(fcate);	
			
			var lidiv = document.createElement("li"); 
			lidiv.innerHTML = '你还没有关注任何分类<br/><a href="index.html">赶紧关注一个吧</a>'
			iFocusCateList.appendChild(lidiv);	
		}
	}

}

//鼠标移到+上的效果
$(document).ready(function(){
	$('#AllCateList B').live('mouseover',function(e){
		var XTip = "<div id='XTip'>添加关注</div> ";
		$("body").append(XTip);
		$("#XTip").css({
			"top":(e.pageY+10)+"px",
			"left":(e.pageX+10)+"px",
			"position":"absolute",
			"background-color":"#FFFFCC",
			"padding":"5px",
			"border":"1px solid #ccc"
		}).show("fast");
	});
	$('#AllCateList B').live('mouseout',function(){
		$("#XTip").remove();
	});
	$('#AllCateList B').live('mousemove',function(e){
		$("#XTip").css({
			"top":(e.pageY+10)+"px",
			"left":(e.pageX+10)+"px"
		});
	});	
	$('#AllCateList B').live('click',function(){
		$("#XTip").remove();
		var $par = $(this).parent();
		//alert($par.attr("id"));
		focusCate($par.attr("id"));
	});
});


//鼠标移到X上的效果
$(document).ready(function(){
	$('#iFocusCateList B').live('mouseover',function(e){
		var XTip = "<div id='XTip'>点击此处 取消对该分类的关注</div> ";
		$("body").append(XTip);
		$("#XTip").css({
			"top":(e.pageY+10)+"px",
			"left":(e.pageX+10)+"px",
			"position":"absolute",
			"background-color":"#FFFFCC",
			"padding":"5px",
			"border":"1px solid #ccc"
			
		}).show("fast");
	});
	$('#iFocusCateList B').live('mouseout',function(){
		$("#XTip").remove();
	});
	$('#iFocusCateList B').live('mousemove',function(e){
		$("#XTip").css({
			"top":(e.pageY+10)+"px",
			"left":(e.pageX+10)+"px"	
		});
	});	
	$('#iFocusCateList B').live('click',function(){
		$("#XTip").remove();
		var $par = $(this).parent();
		//alert($par.attr("id"));
		unfocusCate($par.attr("id"));
	});
});

function unfocusCate(cateid)
{
	//alert(userID);
	if(!userID)
	{
		alert("请登录");
		return;
	}
	var url="user/user.php?action=unfocusCate";
	var para="userID="+userID;
	para+="&cate="+cateid;
	var resp=SendPostRequest(url,para);	
	//alert(resp);
	if(resp=="您还没有关注本分类")
	{
		alert(resp);
	}
	else if (resp=="false")
	{
		alert("解除关注此分类失败 请和官方联系");
	}
	else if (resp=="true")
	{
		alert("成功解除对分类的关注");
	}
	//每次取消对某分类的关注之后 都应该刷新关注分类的列表
	getiFocusCateList();
}

function focusCate(cateid)
{
	//alert(userID);
	if(!userID)
	{
		alert("请登录");
		return;
	}
	var url="user/user.php?action=focusCate";
	var para="userID="+userID;
	para+="&cate="+cateid;
	var resp=SendPostRequest(url,para);	
	//alert(resp);
	if(resp=="您已经关注了本分类")
	{
		alert(resp);
	}
	else if (resp=="false")
	{
		alert("关注此分类失败 请和官方联系");
	}
	else if (resp=="true")
	{
		alert("成功关注此分类");
	}
	getiFocusCateList();
}



function getFocusCateList(oid)
{
	var iFocusCateList=document.getElementById('iFocusCateList');	
		//刷新前 先清空子节点
	var childs = iFocusCateList.childNodes;
	for(var i=childs.length-1; i>=0; i--){
		iFocusCateList.removeChild(childs[i]);
	}

	if(oid==""||oid==null)
	{
	}
	else
	{
		var url="user/user.php?action=iFocusCate";
		var para="userID="+oid;
		var resp=SendPostRequest(url,para);
		//alert(resp);
	}
	if(resp!=null || resp != 'false')
	{
		eval("fList="+resp);
		for(var i=0;i<fList.length;i++)
		{	
			var lidiv = document.createElement("li"); 
			lidiv.innerHTML = '<a href="#">'+fList[i].name+'</a><B>×</B>';
			lidiv.setAttribute("id",fList[i].id);
			lidiv.onclick = function(){showCateHelpList(this.getAttribute("id"));}
			iFocusCateList.appendChild(lidiv);	

		}
		if(i==0)
		{
			var lidiv = document.createElement("li"); 
			lidiv.innerHTML = 'ta还没有关注任何分类'
			iFocusCateList.appendChild(lidiv);	
		}
	}

}

function showHelpListOther(type,pageNo)
{
	//将页面回到顶端
    scroll(0,0);
	//页码赋给全局变量
	g_pageNo=pageNo;
	g_taskType=type;
	//alert(type);
	rush();
	var url;//申请的服务器端程序地址
	url="help/Require.php?action="+type;	
	var para="userID="+otherid;
	para+="&pageNo="+pageNo;//页码
	para+="&perPageRecord="+g_perPageRecord;//每页显示记录的条目数

	
	resp=SendPostRequest(url,para);

	taskNoAdminCheck();
}
function submitReqHelp()
{
	var title=document.getElementById('title').value;
	var money=document.getElementById('money').value;
	var cate=document.getElementById('cate').value;
	var description=document.getElementById('description').value;
	var detail=document.getElementById('detail').value;
	var username=getCookie("username");
	var userID=getCookie("userID");
	alert(username);
	alert(userID);
	//alert("debug");
	//TODO 上传附件和照片
	
	if(username==null || username=="" || userID==null || userID=="")
	{
		alert("请先登录");
	}
	else if(title==""||title==null)
	{
		alert("求助的时候 标题还是不要为空的好！");
	}
	else
	{
		var url="help/help.php?action=reqHelp";
		var para="&title="+title;
		para +="&money="+money;
		para +="&cate="+cate;
		para +="&description="+description;
		para +="&detail="+detail;
		para +="&username="+username;
		para +="&userID="+userID;
		resp=SendPostRequest(url,para);

		alert(resp);
		
		if(resp=="存在同名标题 请修正标题")
			alert('存在同名标题 请修正标题');

		if(resp=="false")
			alert('发布Help需求失败');	
		
		if(resp=="true")
		{
			alert('发布Help需求成功 您的活跃度+3');
			window.location.href="user.html";

		}	
	}
}